<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar
      title="编辑昵称"
      left-text="取消"
      right-text="确定"
      @click-left="$emit('closePop', false)"
      @click-right="doEdit"
    />
    <!-- /导航栏 -->
    <van-field
      v-model="uName"
      rows="2"
      autosize
      type="textarea"
      maxlength="20"
      placeholder="请输入新昵称"
      show-word-limit
    />
  </div>
</template>

<script>
import { editUser } from '@/api/user.js';

export default {
  name: 'update-name',
  props: {
    usrInfo: {
      required: true,
      type: Object,
    },
  },
  data() {
    return {
      uName: '',
    };
  },
  created() {
    this.uName = this.usrInfo.name;
  },
  methods: {
    // 执行修改
    async doEdit() {
      try {
        await editUser({ name: this.uName });
        this.$toast.success('修改成功 : )');
        this.$emit('closePop', false);
        // 修改父组件的 名字
        this.usrInfo.name = this.uName;
      } catch (err) {
        this.$toast.fail('修改失败 : (');
      }
    },
  },
  computed: {},
  watch: {},
  components: {},
};
</script>

<style lang="less" scoped>
/deep/ .van-nav-bar__text {
  color: #fff !important;
}
</style>
